﻿using Bussiness.Interface;
using Bussiness.Service;
using Common;
using Common.Model;
using Model;
using System;
using System.Collections.Generic;

public partial class MasterPage : System.Web.UI.MasterPage
{
    IBaseService baseService = new BaseService();
    Users user = new Users();
    protected void Page_Load(object sender, EventArgs e)//页面加载执行事件
    {
        user = (Users)Session["user"];
        if (Session["user"] != null)
        {
            LoginOut.Style["display"] = "block";//显示退出按钮
            LoginUser.InnerText = user.UserName;
            if (user.UserType == "Admin")
            {
                admin.Style["display"] = "block";
            }
            else if (user.UserType == "Emp")
            {
                admin.Style["display"] = "block";
            }
        }
    }
    protected void Loin_Click(object sender,EventArgs e)//登录/注册标签点击事件
    {
            if (Session["user"] != null)//判断是否登录
            {
                Response.Write("<script>alert('请勿重复登录')</script>");
            }
            else
            {
                Response.Redirect("Login.aspx", false);
            }
       
    }
    protected void LoginOut_Click(object sender, EventArgs e)//退出按钮
    {
        Session["user"] = null;
        user = (Users)Session["user"];//清空user控制器的里值
        Server.Transfer("Index.aspx");//重新载入首页
    }
    protected void AdminLogin_Click(object sender, EventArgs e)//管理员登录
    {
        try
        {
            if (user.UserName != "")//判断是否登录
            {
                Result<Users> re = baseService.QuerySingle<Users>(p => p.Name == user.UserID, c => c.UserType == Enums.UserType.Admin.ToString());
                if (re.Success)
                {
                    StaticConstant.CopUser = user.UserName;
                    Response.Redirect("~/bgadmin/bgIndex.aspx", false);
                }
                else
                {
                    Response.Write("<script>alert('当前账户不是管理员')</script>");
                }
            }
        }
        catch
        {
            Response.Redirect("Login.aspx", false);
        }
    }
    protected void Search_ServerClick(object sender, EventArgs e)//搜索时间
    {
        string id = Search_value.Value;
        Response.Redirect("LeftMenShow.aspx?seachvalue="+id+"");
    }
}
